package com.deity.deitymvp.V.Impl;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.deity.deitymvp.Bean.DataBean;
import com.deity.deitymvp.P.Impl.PI;
import com.deity.deitymvp.R;
import com.deity.deitymvp.V.Interface.IV;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.finalteam.okhttpfinal.OkHttpFinal;
import cn.finalteam.okhttpfinal.OkHttpFinalConfiguration;

public class MainActivity extends AppCompatActivity implements IV {

    @Bind(R.id.tv)
    TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        //初始化网络访问框架
        OkHttpFinalConfiguration.Builder builder = new OkHttpFinalConfiguration.Builder();
        OkHttpFinal.getInstance().init(builder.build());

        //MVP的启动处，这里只要一被调用整个MVP就运行起来了
        PI pi = new PI(this);
        pi.loadData();
    }

    @Override
    public void loadData(DataBean dataBean) {
        tv.setText(dataBean.getText());
    }

    //返回错误信息
    @Override
    public void loadDataErr(int errorCode, String msg) {
        tv.setText("网络访问出错！错误码是：" + errorCode + "；错误信息是：" + msg);
    }


}
